package org.stormphoenix.bbsfamily

import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import springfox.documentation.builders.ApiInfoBuilder
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.service.ApiInfo
import springfox.documentation.service.Contact
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket
import springfox.documentation.swagger2.annotations.EnableSwagger2

/**
 * SwaggerConfig 必须与 App 在同级目录下，否则 swagger-ui 会失效
 */
@Configuration
@EnableSwagger2
class SwaggerConfig {

    @Value("\${bbs.name}")
    lateinit var bbsTitle: String

    @Bean
    fun createRestfulApi(): Docket {
        return Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("org.stormphoenix.bbsfamily.controller"))
            .build()
    }

    private fun apiInfo(): ApiInfo {
        return ApiInfoBuilder()
            .title("$bbsTitle Api")
            .contact(Contact("stormphoenix", "null", "stormphoenix.hzau@hotmail.com"))
            .version("0.1")
            .termsOfServiceUrl("localhost:8080/")
            .description("bbs api")
            .build()
    }
}